package com.lmx.persistence.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lmx.common.constants.CommonConstants;
import com.lmx.common.constants.LeaveStatus;
import com.lmx.common.util.CommonUtil;
import com.lmx.persistence.service.common.BaseCrudServiceImpl;
import com.lmx.repoDomain.tmodel.CustomerEvent;
import com.lmx.repoDomain.tmodel.CustomerLeave;
import com.lmx.repoDomain.tmodel.Dicttype;

/**
 * 老人世家service实现
 *
 * @author ytche
 * @date 2017年9月9日
 *
 */
@Service
public class CustomerEventServiceImpl extends BaseCrudServiceImpl<CustomerEvent> implements
		CustomerEventService {
	@Autowired
	private DicttypeService dicService;

	@Override
	public void sysLeaveEvent(CustomerLeave customerLeave, Integer today) {
		today = today == null ? CommonUtil.getCurrTimes() : today;
		CustomerEvent event = new CustomerEvent();
		event.setCustomer(customerLeave.getCustomer());
		event.setEventFlag(CommonConstants.DEFAULT_STATUS_NO_0);
		event.setTenant(customerLeave.getTenant());
		event.setEventTime(today);
		if (LeaveStatus.LEAVING.getValue().equals(customerLeave.getStatus())) {
			event.setName("请假");
			Dicttype dicttype = dicService.findById(CommonConstants.EVENT_TYPE.LEAVEING.lable());
			event.setType(dicttype);
		}
		if (LeaveStatus.LEAVE_COMPLETE.getValue().equals(customerLeave.getStatus())) {
			event.setName("销假");
			Dicttype dicttype = dicService.findById(CommonConstants.EVENT_TYPE.LEAVE_COMPLETE
					.lable());
			event.setType(dicttype);
		}
		super.save(event);
	}
}
